package com.yoda.mall.admin.service;

import com.yoda.mall.api.HomeRecommendSubjectApi;
import com.yoda.mall.api.SubjectApi;
import com.yoda.mall.model.dto.HomeProductDto;
import com.yoda.mall.model.dto.SubjectDto;
import com.yoda.mall.model.entity.cms.Subject;
import com.yoda.mall.model.entity.sms.HomeRecommendProduct;
import com.yoda.mall.model.entity.sms.HomeRecommendSubject;
import com.yoda.mall.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shawn
 * @date 2022年 12月 17日 11:35
 */
@Service
public class SubjectService {

    @DubboReference
    private SubjectApi subjectApi;

    @DubboReference
    private HomeRecommendSubjectApi homeRecommendSubjectApi;


    public PageResult<Subject> selectByPage(String keyword, Integer page, Integer pageSize) {
        return subjectApi.selectByPage(page,pageSize,keyword);
    }

    public Integer createRecommendSubject(List<SubjectDto> homeSubjectList) {
        if (homeSubjectList.size()==0){
            return 0;
        }
        List<HomeRecommendSubject> homeRecommendSubjects = homeSubjectList.stream().map(SubjectDto::initRecommendSubject).collect(Collectors.toList());
        return homeRecommendSubjectApi.createRecommendProduct(homeRecommendSubjects);
    }

    public List<Subject> getAllSubject() {
        return subjectApi.getAllSubject();
    }

    /**
     * 获取全部商品专题
     * @return
     */
    public List<Subject> subjectArr() {
     return subjectApi.subjectArr();

    }
}
